<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>
  <head>
  <base target="_self"/>
  
  <title>门户信息添加页面</title>
  	<meta http-equiv="X-UA-Compatible" content="IE=7" />
  	<%@ include file="../jslib/jquerylib.jsp" %>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/DatePicker/WdatePicker.js" defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/js_css_image/js/base/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/additional-methods.js"></script>
    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if>
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    $().ready(function() {
    	// 准备好Options对象
    	var options = {
          	    url:'portletAction!addsavePortlet.action',
          	    beforeSubmit:checkForm,
          	    dataType:'json',
          	    success: function(data) {
          	      if(data.result=='success'){
        			alert("添加成功!");
        			api.close();
        			W.refreshIt();
          	      }
          	    }};
        		$('#saveBtn').click(function(){
        			    	$('#pageFrom').ajaxSubmit(options);
        	 	            return false;
            	 });
        		$('#closeBtn').click(function(){
        			api.close();
            	 });
});

		 function checkForm(){
			var flag = true;
			if($.trim($("#portletName").val()) == ""){
					alert("请填写门户名称!");
					$("#portletName").focus();
					return false;
				}else if(!checkExp1($("#portletName").val())){
					alert("门户名称不能含有如下特殊符号：\" # $ \, \' \\");
					$("#portletName").focus();
					return false;
				} 
				if($("#portletHeight").val() != ""){
					if(!checkExp1($("#portletHeight").val())){
						alert("门户高度不能含有如下特殊符号：\" # $ \, \' \\");
						$("#portletHeight").focus();
						return false;	
					}else if(!checkExp2($("#portletHeight").val())){
						alert("门户高度请输入非负数值");
						$("#portletHeight").focus();
						return false;
					}
				}
				if($("#portletSort").val() != "" ){
					if(!checkExp1($("#portletSort").val())){
						alert("排序字段不能含有如下特殊符号：\" # $ \, \' \\");
						$("#portletSort").focus();
						return false;
					}else if(!checkExp($("#portletSort").val())){
						alert("排序字段请输入非负整数");
						$("#portletSort").focus();
						return false;
					}
				}
		}
		//验证input长度
		function inputCountintlen(input){
			var result = $("#customName").val().length;
			if (result > 40) {
				return false;
			}else{
				return true;
			}
		}		
	
		//验证大于等于0整数
		function checkExp(inputData){ //  /^[0-9]*[1-9][0-9]*$/  
			var regEx = new RegExp(/^([1-9]\d{0,}|0)$/);
			var result = inputData.match(regEx);
			if (result == null) {
			return false;
			}
			return true;
		}
		//验证非负数
		function checkExp2(inputData){ 
			var regEx = new RegExp(/^\d+(\.{0,1}\d+){0,1}$/);
			//var regEx = new RegExp(/^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/); 小数点后保留两位
			var result = inputData.match(regEx);
			if (result == null) {
			return false;
			}
			return true;
		}
		//验证特殊字符
		function checkExp1(inputData){ 
			var regEx = new RegExp(/^(([^$,"'#\\])*)$/);
			var result = inputData.match(regEx);
			if (result == null) {
			return false;
			}
			return true;
		}
		
		function countlen(textarea){
		    if (textarea.value.length> 250){
		        alert("最多为250个字符,字符输入超出限制!");
		        textarea.value=textarea.value.substring(0,250);
		    }
		    return true;
		}
		
		
		
   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 575px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body>
  	<form action="" id="pageFrom" name="" method="post">
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		<input type="hidden" id="id" name="id" value="${param.pId}"  style="width:340px"/>
		  <tr>
		    <td align="right">门户名称：</td>
		    <td align="left">
			    <div class="div">
					<input maxlength="40" type="text" id="portletName" name="portletName" value=""  style="width:215px"/>
					<img src="<%=request.getContextPath() %>/images/xh.png"></img>
				</div>
		    </td>
		    <td align="right">门户URL：</td>
		    <td> 
			    <div class="div">
					<input maxlength="50" type="text" id="portletUrl" name="portletUrl" value="" style="width:200px"/>
				</div>
		    </td>
		  </tr>
		  <tr>
		    <td align="right">执行类型：</td>
		    <td> 
			    <div class="div">
					<input maxlength="40" type="text" id="executeType" name="executeType" value="" style="width:215px"/>
				</div>
		    </td>
		    <td align="right">门户SQL语句：</td>
		    <td> 
			    <div class="div">
					<input maxlength="200" type="text" id="portletSql" name="portletSql" value="" style="width:200px"/>
				</div>
		    </td>
		  </tr>
		 <tr>
		    <td align="right">状态：</td>
		    <td> 
			    <div class="div">
					<select id="state" name="state" style="width: 220px;">
						<!--<option value="">请选择</option>  -->
						<option value="正常">正常</option>
						<option value="停用">停用</option>
					</select>
				</div>
		    </td>
		 
		    <td align="right">门户高度：</td>
		    <td> 
			    <div class="div">
					<input maxlength="9" type="text" id="portletHeight" name="portletHeight" value="" style="width:200px"/>
				</div>
		    </td>
		    
		  </tr>
		  <tr>
		    <td align="right">显示位置：</td>
		    <td> 
			    <div class="div">
					<select id="location" name="location" style="width: 220px;">
						<option value="">请选择</option>
						<option value="0">整行</option>
						<option value="1">一行两列</option>
						<option value="2">一行三列</option>
					</select>
				</div>
		    </td>
		 
		    <td align="right">排序字段：</td>
		    <td> 
			    <div class="div">
					<input maxlength="9" type="text" id="portletSort" name="portletSort" value="" style="width:200px"/>
				</div>
		    </td>
		    
		  </tr>
		  <tr>
		    <td align="right" >备注：</td>
		    <td colspan="4" >
		    	<div class="div">
					<textarea  rows="3" cols="160" id="remarks" name="remarks" onkeydown="countlen(this)"></textarea>
				</div>	
		    </td>
		  </tr>
		  <tr>
		    <td align="center" colspan="4" >
		    	<input type="button" id="saveBtn" value="保 存" class="form_bt_orange" />
		      	<input type="button" id="closeBtn" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		</table>
	</form>
  </body>
</html>
